﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Triggers.CApEditTriggerEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.Triggers;

public class CApEditTriggerEnabler : ITxCommandEnabler
{
  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    bool flag = false;
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      flag = false;
    else if (this.GetSelectesItemsCount() == 1)
    {
      TxObjectList selectedObject = this.GetSelectedObject();
      if (selectedObject != null && ((Collection<ITxObject>) selectedObject).Count == 1)
        flag = true;
    }
    return flag;
  }

  private int GetSelectesItemsCount() => TxApplication.ActiveSelection.Count;

  private TxObjectList GetSelectedObject()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxRoboticPaintTrigger));
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
    return ((Collection<ITxObject>) filteredItems).Count > 0 ? filteredItems : (TxObjectList) null;
  }
}
